home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / db.h < prev    next >
C/C++ Source or Header  |  1989-06-23  |  3KB  |  88 lines

  1. /*
  2.  * db.h --
  3.  *
  4.  *    Declarations of constants and structures for the db module.
  5.  *
  6.  * Copyright 1987, 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/lib/include/RCS/db.h,v 1.7 89/06/23 11:27:53 rab Exp $ SPRITE (Berkeley) 
  16.  */
  17.  
  18. #ifndef _DB
  19. #define _DB
  20.  
  21. /*
  22.  * A file can be locked for the entire duration it is open (for example,
  23.  * scanning the entire database for records), each time it is written or
  24.  * read (for example, when updating the shared load average file one might
  25.  * want to leave it open but lock it only during updates), or not at all
  26.  * for example, the file specific to a host that is shared between one process
  27.  * updating it and one process reading it, each atomic).
  28.  */
  29. typedef enum {
  30.     DB_LOCK_OPEN,        /* lock the file on open and keep it locked
  31.                  * until close. */
  32.     DB_LOCK_ACCESS,        /* lock should be obtained each time
  33.                  * the file is accessed. */
  34.     DB_LOCK_NEVER,        /* do not lock the file at all */
  35.     DB_LOCK_READ_MOD_WRITE,    /* lock should be obtained when the file
  36.                  * is read and released when it is
  37.                  * written. */
  38. } Db_LockWhen;
  39.  
  40. /*
  41.  * Action to take when obtaining a lock: abort immediately, poll for a
  42.  * timeout period, poll forever, or poll but break the lock upon timeout.
  43.  * DB_LOCK_NONE is equivalent to DB_LOCK_NEVER but is used for the single
  44.  * open + read/write + close interface.
  45.  */
  46. typedef enum {
  47.     DB_LOCK_NO_BLOCK,        /* return immediately with error */
  48.     DB_LOCK_POLL,        /* poll the lock; time out if necessary */
  49.     DB_LOCK_WAIT,        /* wait indefinitely */
  50.     DB_LOCK_BREAK,        /* poll, plus break the lock if needed */
  51.     DB_LOCK_NONE,        /* do not lock the file at all */
  52. } Db_LockHow;
  53.  
  54. /*
  55.  * Information used for repeated scanning through database.
  56.  */
  57.  
  58. typedef struct {
  59.     int          streamID;    /* stream identifier for the open file */
  60.     int          lockType;    /* LOCK_{SH,EX} */
  61.     Db_LockWhen      lockWhen;    /* See above */
  62.     Db_LockHow       lockHow;    /* See above */
  63.     int          structSize;    /* size of one entry */
  64.     int          index;    /* current index into file */
  65.     int          firstRec;      /* index of first record stored in buffer */
  66.     int          numBuf;      /* number of records in buffer */
  67.     char      *buffer;    /* pointer to buffer containing records */
  68.     char      *fileName;    /* name of database file, for error messages */
  69. } Db_Handle;
  70.  
  71. extern int     Db_Open();
  72. extern int     Db_Close();
  73.  
  74. /*
  75.  * The following two routines perform (optional lock)/io/(optional unlock)
  76.  * together.
  77.  */
  78. extern int     Db_Get();
  79. extern int     Db_Put();
  80.  
  81. /*
  82.  * The following two routines perform open/lock/io/unlock/close together.
  83.  */
  84. extern int     Db_WriteEntry();
  85. extern int     Db_ReadEntry();
  86.  
  87. #endif /* _DB */
  88.